package cn.christ.com.mobilesafe.modle;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class AppLockDao {
	private AppLockHepler dbHelper;

	public AppLockDao(Context context) {
		dbHelper = new AppLockHepler(context);
	}

	// add
	public void add(String packageName) {
		SQLiteDatabase db = dbHelper.getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put("packageName", packageName);
		db.insert("app_lock", null, values);
		db.close();
	}

	// remove
	public void remove(String packageName) {
		SQLiteDatabase db = dbHelper.getWritableDatabase();
		db.delete("app_lock", "packageName=?", new String[] { packageName });
		db.close();
	}

	// find
	public boolean find(String packageName) {
		SQLiteDatabase db = dbHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery("select count(*) from app_lock where packageName=?", new String[] { packageName });
		if (cursor != null) {
			if (cursor.moveToNext()) {
				int count = cursor.getInt(0);
				if (count > 0) {
					cursor.close();
					db.close();
					return true;
				}
			}
		}
		db.close();
		return false;
	}

}
